package top.healthylife.gateway.platform.lexin.dto.lexinjxelements.res;

import cn.hutool.core.util.ObjectUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author : GaoZeXi
 * @date 2021/9/9 15:32
 */
@Data
@Accessors(chain = true)
@ApiModel("晶信结果分")
public class JxElements {
    @ApiModelProperty(value = "晶信三要素评分" , example = "[300.000,900.000]" , required = false , notes = "通过用户的综合行为和三方数据评定其欺诈风险评分")
    private String jx3elementsScore;

    @ApiModelProperty(value = "消费稳定性" , example = "1，2，3，4，5 -1 为未查得" , required = false , notes = "根据用户在电商平台消费行为评定其稳定性")
    private String jxStabilityLev;

    @ApiModelProperty(value = "消费能力" , example = "[0, 100]" , required = false , notes = "根据用户在电商平台消费信息评定其购买力")
    private String jxBuyingInd;

    @ApiModelProperty(value = "消费风险" , example = "[0, 100]" , required = false , notes = "根据用户在电商平台消费信息评定其涉及高危类交易的程度")
    private String jxRiskInd;

    @ApiModelProperty(value = "消费理性" , example = "[0, 100]" , required = false , notes = "根据用户在电商平台消费信息评定其冲动消费的可能性")
    private String jxResonableConsumingInd;

    @ApiModelProperty(value = "履约能力" , example = "[0, 100]" , required = false , notes = "根据用户在电商平台消费信息评定其履约能力")
    private String jxPerformanceInd;

    @ApiModelProperty(value = "收入能力" , example = "[0, 100]" , required = false , notes = "根据用户在电商平台消费信息和三分数据综合评定其收入")
    private String jxIncommingInd;

    @ApiModelProperty(value = "交易城市偏好" , example = "中国293个地级行政区" , required = false , notes = "根据用户在电商平台消费信息评定其交易发生频数最高的城市")
    private String jxCity;

    @ApiModelProperty(value = "消费圈规模指数" , example = "[0, 100]" , required = false , notes = "根据用户在电商平台消费信息评定其消费关系人规模等级")
    private String jxComsumingSocialInd;

    @ApiModelProperty(value = "高危时段交易偏好" , example = "[0, 100]" , required = false , notes = "根据用户在电商平台消费信息评定其在高危时间段消费的偏好程度")
    private String jxIiskPeriodConsumingInd;

    @ApiModelProperty(value = "高危品类交易偏好" , example = "[0, 100]" , required = false , notes = "根据用户在电商平台消费信息评定其高危品类消费行为")
    private String jxRiskCategoryConsumingInd;

    @ApiModelProperty(value = "工作时段交易偏好" , example = "[0, 100]" , required = false , notes = "根据用户在电商平台消费信息综合评定其工作日工作时间段消费偏好程度")
    private String jxWorkingtimeShoppingInd;

    @ApiModelProperty(value = "移动购物偏好" , example = "1，2，3，4，5 -1 为未查得" , required = false , notes = "客户依赖手机进行日常网购的偏好程度")
    private String jxCellphonePreferenceLev;

    @ApiModelProperty(value = "线上消费偏好" , example = "[0, 100]" , required = false , notes = "客户近期使用电商平台的活跃度")
    private String jxEcomActivenessInd;

    @ApiModelProperty(value = "线上消费账龄等级" , example = "1，2，3，4，5 -1 为未查得" , required = false , notes = "客户在电商平台的注册时长指标")
    private String jxEcomAccountHistoryLev;

    @ApiModelProperty(value = "快递地址稳定性" , example = "1，2，3，4，5 -1 为未查得" , required = false , notes = "客户电商收货地址的稳定程度")
    private String jxEcomAddrStabilityLev;

    @ApiModelProperty(value = "快递联系稳定性" , example = "1，2，3，4，5 -1 为未查得" , required = false , notes = "客户电商联系方式的稳定程度")
    private String jxEcomCellphoneStabilityLev;

    @ApiModelProperty(value = "晶信三要素评分-反解析京东分" , example = "" , required = false , notes = "")
    private String jdModuleJx3elementsScore;

//    public static void main(String[] args) {
//        JxElements jxElements = new JxElements().setJx3elementsScore("653.952");
//        System.out.println("jdModuleJx3elementsScore = " + jxElements.getJdModuleJx3elementsScore());
//    }

    public String getJdModuleJx3elementsScore(){
        int minOri = 300;
        int maxOri = 900;
        int minNew = 500;
        int maxNew = 750;
        int diffMaxMinOri =maxOri-minOri;
        int diffMaxMinNew =maxNew-minNew;
        float v;
        try {
            v = Float.parseFloat(this.jx3elementsScore);
        }catch (Exception e){
            return "-1";
        }
        if(ObjectUtil.isNull(v)||v==-1){
            return "-1";
        }else{
            float xNew = minNew+((v-minOri)/diffMaxMinOri)*diffMaxMinNew;
            if(xNew<minNew||xNew>maxNew){
                return "-1";
            }
            return String.format("%.3f",xNew);
        }
    }
}
